'use strict';
const {
+ ArrayIsArray,
ArrayPrototypeIndexOf,
ArrayPrototypePush,
ArrayPrototypeShift,
ObjectSetPrototypeOf(Agent, HttpAgent);
Agent.prototype.createConnection = createConnection;
+function getPfxAgentKey(pfx, passphrase) {
+ if (!ArrayIsArray(pfx))
+ return pfx;
+
+ let key = '';
+ for (let i = 0; i < pfx.length; i++) {
+ const value = pfx[i];
+ const raw = value?.buf || value;
+ const pass = value?.passphrase || passphrase;
+ key += `:${raw}:${pass}`;
+ }
+ return key;
+}
+
/**
* Gets a unique name for a set of options.
* @param {{
name += ':';
if (options.pfx)
- name += options.pfx;
+ name += getPfxAgentKey(options.pfx, options.passphrase);
name += ':';
if (options.rejectUnauthorized !== undefined)
const assert = require('assert');
const https = require('https');
+const fixtures = require('../common/fixtures');
const agent = new https.Agent();
'::secureProtocol:c,r,l:false:ecdhCurve:dhparam:0:sessionIdContext:' +
'"sigalgs":privateKeyIdentifier:privateKeyEngine'
);
+
+{
+ const baseOptions = {
+ host: '0.0.0.0',
+ port: 443,
+ };
+
+ const agent1 = fixtures.readKey('agent1.pfx');
+ const agent6 = fixtures.readKey('agent6.pfx');
+
+ assert.notStrictEqual(
+ agent.getName({
+ ...baseOptions,
+ pfx: [{ buf: agent1, passphrase: 'sample' }],
+ }),
+ agent.getName({
+ ...baseOptions,
+ pfx: [{ buf: agent6, passphrase: 'sample' }],
+ })
+ );
+
+ assert.notStrictEqual(
+ agent.getName({
+ ...baseOptions,
+ pfx: [{ buf: agent1, passphrase: 'sample' }],
+ }),
+ agent.getName({
+ ...baseOptions,
+ pfx: [{ buf: agent1, passphrase: 'different' }],
+ })
+ );
+
+ assert.notStrictEqual(
+ agent.getName({
+ ...baseOptions,
+ pfx: [{ __proto__: { buf: agent1, passphrase: 'sample' } }],
+ }),
+ agent.getName({
+ ...baseOptions,
+ pfx: [{ __proto__: { buf: agent6, passphrase: 'sample' } }],
+ })
+ );
+}
--- /dev/null
+'use strict';
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+
+const assert = require('assert');
+const https = require('https');
+const fixtures = require('../common/fixtures');
+
+const server = https.createServer({
+ key: fixtures.readKey('agent2-key.pem'),
+ cert: fixtures.readKey('agent2-cert.pem'),
+ requestCert: true,
+ rejectUnauthorized: false,
+}, common.mustCall((req, res) => {
+ res.end(req.socket.getPeerCertificate().subject.CN);
+}, 2));
+
+server.listen(0, common.mustCall(async () => {
+ const agent = new https.Agent({ keepAlive: true, maxSockets: 1 });
+ const port = server.address().port;
+
+ const first = await request({
+ agent,
+ port,
+ pfx: [{ buf: fixtures.readKey('agent1.pfx'), passphrase: 'sample' }],
+ });
+ assert.strictEqual(first.body, 'agent1');
+ assert.strictEqual(first.reusedSocket, false);
+
+ const second = await request({
+ agent,
+ port,
+ pfx: [{ buf: fixtures.readKey('agent10.pfx'), passphrase: 'sample' }],
+ });
+ assert.strictEqual(second.body, 'agent10.example.com');
+ assert.strictEqual(second.reusedSocket, false);
+
+ agent.destroy();
+ server.close();
+}));
+
+function request(options) {
+ return new Promise((resolve, reject) => {
+ const req = https.get({
+ ...options,
+ rejectUnauthorized: false,
+ }, common.mustCall((res) => {
+ let body = '';
+ res.setEncoding('utf8');
+ res.on('data', (chunk) => body += chunk);
+ res.on('end', common.mustCall(() => {
+ resolve({ body, reusedSocket: req.reusedSocket });
+ }));
+ }));
+ req.on('error', reject);
+ });
+}